package com.techsoul.module.pms.controller;

import com.techsoul.common.core.pojo.Result;
import com.techsoul.module.pms.pojo.param.TbWmsMaterialInLocationSaveParam;
import com.techsoul.module.pms.pojo.param.TbWmsMaterialInLocationSearchParam;
import com.techsoul.module.pms.pojo.param.TbWmsMaterialInventoryLendingSaveParam;
import com.techsoul.module.pms.pojo.vo.TbWmsMaterialInLocationApiVo;
import com.techsoul.module.pms.service.ITbWmsMaterialInLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;

/**
 * 货区货物清单 Controller
 *
 * @author liuen
 * @date 2022-01-25
 */
@Api(tags = "货区货物清单")
@RestController
@RequestMapping("/web/tbWmsMaterialInLocation")
public class TbWmsMaterialInLocationController {

    @Autowired
    private Result result;
    
    @Autowired
    private ITbWmsMaterialInLocationService service;

    @ApiOperation("新增")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialInLocation:insert')")
    @PostMapping
    public Result insert(@Valid @RequestBody TbWmsMaterialInLocationSaveParam params) {
        return result.success(this.service.insert(params));
    }

    @ApiOperation("批量删除（多个用逗号隔开）")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialInLocation:delete')")
    @DeleteMapping("/{ids}")
    public Result batchDelete(@PathVariable String[] ids) {
        return result.success(this.service.batchDelete(Arrays.asList(ids)));
    }

    @ApiOperation("修改")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialInLocation:update')")
    @PutMapping
    public Result update(@Valid @RequestBody TbWmsMaterialInLocationSaveParam params) {
        return result.success(this.service.update(params));
    }

    @ApiOperation("详情")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialInLocation:search')")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id) {
        return result.success(this.service.findById(id));
    }

    @ApiOperation("列表")
   // @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialInLocation:search')")
    @PostMapping("/search")
    public Result findAll(@RequestBody TbWmsMaterialInLocationSearchParam params) {
        return result.success(this.service.findAll(params));
    }

    @ApiOperation("列表")
    // @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialInLocation:search')")
    @PostMapping("/countBySkuCode")
    public Result countBySkuCode(@RequestBody TbWmsMaterialInLocationSearchParam params) {
        return result.success(this.service.countBySkuCode(params.getSkuCode()));
    }

    @ApiOperation("列表")
    @PostMapping("/queryDataInfoList")
    public Result queryDataInfoList(@RequestBody TbWmsMaterialInLocationApiVo params) {
        return result.success(this.service.queryDataInfoList(params));
    }
    @ApiOperation("列表-分页")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialInLocation:search')")
    @PostMapping("/search/{current}/{pageSize}")
    public Result findAll(@RequestBody TbWmsMaterialInLocationSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(this.service.findAll(params, current, pageSize));
    }
    @ApiOperation("列表-分页")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialInLocation:vehicleInLocationSearch')")
    @PostMapping("/vehicleInLocationSearch/{current}/{pageSize}")
    public Result vehicleInLocationSearch(@RequestBody TbWmsMaterialInLocationSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(this.service.findAll(params, current, pageSize));
    }

    @ApiOperation("库存外借或者维修")
    //@PreAuthorize("hasAnyAuthority('web:tbWmsMaterialInLocation:update')")
    @PostMapping("/InventoryLending")
    public Result inventoryLending(@RequestBody TbWmsMaterialInventoryLendingSaveParam params) {
        return result.success(this.service.inventoryLending(params));
    }

    @ApiOperation("库存外借或者维修归还")
    //@PreAuthorize("hasAnyAuthority('web:tbWmsMaterialInLocation:update')")
    @PostMapping("/returnCar")
    public Result returnCar(@RequestBody TbWmsMaterialInventoryLendingSaveParam params) {
        return result.success(this.service.returnCar(params));
    }
}
